# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  def time_since(time)
    dif = Time.now - time
    if dif < 60
      secs = dif.to_i
      ' '+pluralize(secs,'second') + ' ago'
    elsif dif < 3600 
      mins = (dif/60).to_i
      ' '+pluralize(mins,'minute') + ' ago'
    elsif dif < 86400
      hours = (dif/3600).to_i
      ' '+pluralize(hours,'hour') + ' ago'
    elsif dif < 604800
      days = (dif/86400).to_i
      ' '+pluralize(days,'day') + ' ago'
    elsif dif < 2419200
      weeks = (dif/604800).to_i
      ' '+pluralize(weeks,'week') + ' ago'
    elsif dif < 29030400
      months = (dif/2419200).to_i
      ' '+pluralize(months,'month') + ' ago'
    else
      years = (dif/29030400).to_i
      ' '+pluralize(years,'year') + ' ago'
    end    
  end
end
